package testplugin;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.emf.ecore.EObject;

import fr.inria.atlanmod.dummy.Mock;

public class VerificationJob extends Job
{
	
	/**
	 * The element that triggered the model verification 
	 */
	private EObject modifiedObject;

	
	/**
	 * The result of the model verification
	 */
	private boolean markersNeeded;

	/**
	 * The component that launched the job
	 */
	private PapyrusListener papyruslistener;

	/**
	 * 
	 * @param name The name of the job
	 */
	public VerificationJob(String name)
	{
		super(name);
		markersNeeded=false;
		
	}

	/**
	 * Execute the model verification. If the verification detects errors, display the errors.
	 */
	@Override
	protected IStatus run(IProgressMonitor monitor) 
	{
		markersNeeded=papyruslistener.getMock().verifyModel(modifiedObject);
		
		
		//if(true)
		if(markersNeeded) 
		{
			papyruslistener.showMarkersAndHighlight(papyruslistener.getMock().getObjectsToMark());
		}
		return Status.OK_STATUS;
	}
	
	@Override
	protected void canceling() 
	{
		
		papyruslistener.getMock().cancelVerifyModel();

	}

	public void setModifiedObject(EObject modifiedObject) {
		this.modifiedObject = modifiedObject;
	}
	

	public void setPapyruslistener(PapyrusListener papyruslistener) {
		this.papyruslistener = papyruslistener;
	}

}
